<template>
  <div>
    <!-- <p class="pinformation">样品统计</p>
    <el-form :model="form" ref="formRef" label-width="150">
      <el-row>
        <el-form-item label="已交接样品编号总数：">
          {{ form.withSampleCodeCount }}
        </el-form-item>
        <el-form-item
          label="已交接样品编号×检测项目数："
          label-width="200"
          style="margin-left: 10px"
        >
          {{ form.withSampleCodeCountJcxm }}
        </el-form-item>
        <el-form-item
          label="已领取样品编号×检测项目数："
          label-width="200"
          style="margin-left: 10px"
        >
          {{ form.getSampleCodeCountJcxm }}
        </el-form-item>
        <el-form-item
          label="未领取样品编号数×检测项目数："
          label-width="210"
          style="margin-left: 10px"
        >
          {{ form.notGetSampleCodeCount }}
        </el-form-item>
        <el-form-item label="未领取样品方法数：" style="margin-left: 10px">
          {{ form.notGetMethodCount }}
        </el-form-item>
      </el-row>
    </el-form> -->
    <p class="pinformation">未领取样品搜索</p>
    <el-form ref="queryRef" label-width="80" :model="queryParams">
      <el-row>
        <el-col :span="3">
          <el-form-item label="方法编号：" prop="methodCode" label-width="80">
            <el-input
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
              placeholder="请输入"
              v-model="queryParams.methodCode"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="采样时间：" label-width="80">
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="交接批次：" prop="withNumber" label-width="80">
            <el-input
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
              placeholder="请输入"
              v-model="queryParams.withNumber"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="检测项目：" prop="jcxmName" label-width="80">
            <el-input
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
              placeholder="请输入检测项目"
              v-model="queryParams.jcxmName"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="分析组：" prop="userGroupName" label-width="80">
            <el-input
              @keyup.enter="handleQuery"
              clearable
              maxlength="100"
              placeholder="请输入分析组"
              v-model="queryParams.userGroupName"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-row style="justify-content: center">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <p class="pinformation">未领取样品列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table border :data="tableData" height="25vh" v-loading="loading1">
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="样品编号"
        prop="sampleCode"
        width="200"
      />
      <el-table-column align="center" show-overflow-tooltip label="检测项目" width="100">
        <template #default="scope">
          <span v-html="proxy.getSupAndSub(scope.row.jcxmName)"></span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="方法编号" width="160">
        <template #default="scope">
          <span v-html="proxy.getSupAndSub(scope.row.methodCode)"></span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="方法名称">
        <template #default="scope">
          <span v-html="proxy.getSupAndSub(scope.row.methodName)"></span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="采样日期" width="130">
        <template #default="scope">
          {{ scope.row.cyDate }} {{ scope.row.cyTime }}
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="保存时长" width="90">
        <template #default="scope">
          {{ scope.row.saveTime }} {{ scope.row.timeUnitName }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="交接批次"
        prop="withNumber"
        width="90"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="检测类别"
        prop="jclbName"
        width="90"
      />
      <el-table-column align="center" show-overflow-tooltip label="分析组" width="120">
        <template #default="scope">
          <span v-if="scope.row.userGroupName">{{ scope.row.userGroupName }}</span>
          <span style="color: red" v-else>未关联用户组</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <el-row>
      <p class="pinformation">样品领取列表</p>
      <p class="totalStyle">共 {{ tableData1.length }} 条数据</p>
    </el-row>
    <el-table border :data="tableData1" ref="dataTableRef" v-loading="loading2">
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="领取时间"
        prop="getTime"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="领取人"
        prop="getUserName"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="所属组"
        prop="userGroupName"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="当前节点"
        prop="params.taskName"
      />
      <el-table-column
        show-overflow-tooltip
        label="操作"
        align="center"
        width="90"
        fixed="right"
      >
        <template #default="scope">
          <el-button link type="success" @click="handleView1(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      :class="'el-dialog-theme3'"
      v-model="show"
      fullscreen
      title="查看样品发放详情"
    >
      <record :isHide="true" ref="recordRef"></record>
    </el-dialog>
  </div>
</template>

<script setup>
import { getNoWithList, getYplqFrom, getWithData } from "@/api/taskProgressDetails/index";
import record from "../../../flowable/task/record/index.vue";

const { proxy } = getCurrentInstance();
const tableData = ref([]);
const tableData1 = ref([]);
const total = ref(0);
const queryParams = ref({ pageNum: 1, pageSize: 10 });
const form = ref({});
const dateRange = ref([]);
const loading1 = ref(false);
const loading2 = ref(false);
const projectId = ref("");
const show = ref(false);
const recordRef = ref(null);

function getForm(val) {
  projectId.value = val;
  queryParams.value.projectId = val;
  getYplqFrom(projectId.value).then((res) => {
    form.value = res.data;
  });
  getList();
  getWithList();
}

function getList() {
  loading1.value = true;
  getNoWithList(proxy.addDateRange(queryParams.value, dateRange.value)).then((res) => {
    tableData.value = res.rows;
    total.value = res.total;
    loading1.value = false;
  });
}

function getWithList() {
  loading2.value = true;
  getWithData(projectId.value).then((res) => {
    tableData1.value = res.data;
    loading2.value = false;
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  handleQuery();
}

defineExpose({
  getForm,
});

const heightParams = ref([{ tableName: "data", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

function handleView1(row) {
  show.value = true;
  nextTick(() => {
    recordRef.value.getInfo(row.procInsId);
  });
}
</script>

<style></style>
